<template>
	<view class="body">
		<view class="navbar acea-row row-around">
			<view class="item acea-row row-center-wrapper" :class="{ on: navOn === '0' }" @click="onNav('0')">
				会员
			</view>
			<view class="item acea-row row-center-wrapper" :class="{ on: navOn === '1' }" @click="onNav('1')">
				合伙人
			</view>
		</view>
		<view class="scroll-menu" scroll-x>
			<view class='page_menu'>
				<block v-for="(item, index) in currentVipCardList" :key="index">
					<view class="item">
						<p class="leftTopText" :class="{ opened: isCardOpened(item) }">
							{{ isCardOpened(item) ? '已开通' : '暂未开通' }}</p>
						<image :src="item.image" style="width: 690rpx; height: 320rpx;margin-right: 30rpx;"></image>
					</view>
				</block>
			</view>
		</view>
		<view class="welfareBox">
			<p class="welfareBoxTitle">{{ welfareTitle }}</p>
			<view class="welfareListContainer">
				<view class="welfareListBox" v-for="(item, index) in currentWelfareList" :key="index">
					<image :src="item.image" mode="aspectFit"></image>
					<p>{{ item.name }}</p>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		getUserInfo
	} from '@/api/user.js';
	export default {
		data() {
			return {
				navOn: '0', // 默认显示会员
				vipCardList01: [{
						image: 'http://store-profit-system.oss-cn-shanghai.aliyuncs.com/uniappImg/vip/card01.png',
						name: '白银会员',
						id: 1,
						opened: false
					},
					{
						image: 'http://store-profit-system.oss-cn-shanghai.aliyuncs.com/uniappImg/vip/card02.png',
						name: '黄金会员',
						id: 2,
						opened: false
					},
					{
						image: 'http://store-profit-system.oss-cn-shanghai.aliyuncs.com/uniappImg/vip/card03.png',
						name: '黑金会员',
						id: 3,
						opened: false
					}
				],
				vipCardList02: [{
						image: 'http://store-profit-system.oss-cn-shanghai.aliyuncs.com/uniappImg/vip/card04.png',
						name: '创业合伙人',
						id: 1,
						opened: false
					},
					{
						image: 'http://store-profit-system.oss-cn-shanghai.aliyuncs.com/uniappImg/vip/card05.png',
						name: '门店合伙人',
						id: 2,
						opened: false
					}
				],
				welfareTitle: '开通即享六大特权益',
				welfareList: [{
						image: 'http://store-profit-system.oss-cn-shanghai.aliyuncs.com/uniappImg/vip/welfare01.png',
						name: '生日特权',
						id: 1
					},
					{
						image: 'http://store-profit-system.oss-cn-shanghai.aliyuncs.com/uniappImg/vip/welfare02.png',
						name: '迎新福利',
						id: 2
					},
					{
						image: 'http://store-profit-system.oss-cn-shanghai.aliyuncs.com/uniappImg/vip/welfare03.png',
						name: '购物折扣',
						id: 3
					},
					{
						image: 'http://store-profit-system.oss-cn-shanghai.aliyuncs.com/uniappImg/vip/welfare04.png',
						name: '会籍权益',
						id: 4
					},
					{
						image: 'http://store-profit-system.oss-cn-shanghai.aliyuncs.com/uniappImg/vip/welfare05.png',
						name: '注册有礼',
						id: 5
					},
					{
						image: 'http://store-profit-system.oss-cn-shanghai.aliyuncs.com/uniappImg/vip/welfare06.png',
						name: '升级福利',
						id: 6
					},
					{
						image: 'http://store-profit-system.oss-cn-shanghai.aliyuncs.com/uniappImg/vip/welfare07.png',
						name: '门店分红',
						id: 7
					},
					{
						image: 'http://store-profit-system.oss-cn-shanghai.aliyuncs.com/uniappImg/vip/welfare08.png',
						name: '优先特权',
						id: 8
					},
					{
						image: 'http://store-profit-system.oss-cn-shanghai.aliyuncs.com/uniappImg/vip/welfare09.png',
						name: '专属服务',
						id: 9
					}
				],
				userInfo: {}
			};
		},
		computed: {
			currentVipCardList() {
				return this.navOn === '0' ? this.vipCardList01 : this.vipCardList02;
			},
			currentWelfareList() {
				if (this.navOn === '0') {
					this.welfareTitle = "开通即享六大特权益";
					return this.welfareList.slice(0, 6); // 显示前六个权益
				} else {
					this.welfareTitle = "开通即享九大特权益";
					return this.welfareList; // 显示全部权益
				}
			}
		},
		methods: {
			onNav(type) {
				this.navOn = type;
			},
			// 获取用户信息
			getUserList() {
				getUserInfo().then(res => {
					this.userInfo = res.data;
					this.updateVipStatus();
				});
			},
			updateVipStatus() {
				const {
					yiXingDistributionLevel,
					yiXingShareholderLevel
				} = this.userInfo;
				if (yiXingDistributionLevel && yiXingDistributionLevel.levelUp >= 1) {
					this.vipCardList01.forEach((card, index) => {
						card.opened = index + 1 <= yiXingDistributionLevel.levelUp;
					});
				}
				if (yiXingShareholderLevel && yiXingShareholderLevel >= 1) {
					this.vipCardList02.forEach((card, index) => {
						card.opened = index + 1 <= Math.min(yiXingShareholderLevel, 2); // 最多显示为05
					});
				}
			},
			isCardOpened(card) {
				return card.opened;
			}
		},
		created() {
			this.getUserList();
		}
	}
</script>

<style lang="scss" scoped>
	/* 样式保持不变 */
</style>
<style lang="scss" scoped>
	.body {
		min-height: 100vh;
		background: #181818;
	}

	.navbar {
		position: fixed;
		top: 0;
		left: 0;
		width: 100%;
		height: 76rpx;

		.item {
			font-size: 32rpx;
			color: #FFFFFF;
			line-height: 36px;
			border-bottom: 5rpx solid transparent;

			&.on {
				font-weight: bold;
				border-bottom-color: #fff;
				color: #fff;
			}
		}
	}

	.scroll-menu {
		padding: 0rpx 30rpx;
		padding-top: 120rpx;
		white-space: nowrap;
		overflow-x: auto;
	}

	.page_menu .item {
		display: inline-block;
		position: relative;
	}

	.page_menu .leftTopText {
		position: absolute;
		font-weight: 400;
		font-size: 24rpx;
		width: 153rpx;
		height: 44rpx;
		background: #CEDCEA;
		border-radius: 30rpx 0 30rpx 0;
		opacity: 0.86;
		text-align: center;
		line-height: 44rpx;
	}

	// .leftTopText.opened {
	// 	background: #66FF00;
	// 	/* 已开通的背景颜色 */
	// 	color: #000;
	// 	/* 已开通的文字颜色 */
	// }

	.welfareBox {
		background: #303030;
		border-radius: 20rpx;
		margin: 30rpx;
		padding: 20rpx 30rpx;
		display: flex;
		flex-direction: column;
		justify-content: flex-start;
		align-items: flex-start;
	}

	.welfareBoxTitle {
		width: 100%;
		font-weight: bold;
		font-size: 30rpx;
		line-height: 36px;
		color: #FFFFFF;
		margin-bottom: 20rpx;
	}

	.welfareListContainer {
		display: flex;
		flex-wrap: wrap;
	}

	.welfareListBox {
		width: 30%;
		text-align: center;
		margin: 20rpx 10rpx;
	}

	.welfareListBox image {
		width: 56rpx;
		height: 56rpx;
		object-fit: cover;
	}

	.welfareListBox p {
		font-weight: 400;
		font-size: 26rpx;
		color: #FFFFFF;
		line-height: 36px;
	}
</style>